package cn.wujiangbo.controller.app;

import cn.wujiangbo.annotation.IgnoreAuth;
import cn.wujiangbo.domain.app.AppSwiper;
import cn.wujiangbo.result.PageList;
import cn.wujiangbo.service.app.AppSwiperService;
import cn.wujiangbo.query.app.AppSwiperQuery;
import cn.wujiangbo.controller.base.BaseController;
import cn.wujiangbo.util.DateUtils;
import cn.wujiangbo.result.JSONResult;
import cn.wujiangbo.result.PageList;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.List;

/**
 * 轮播图表 API接口
 * @Author 波波老师(weixin:javabobo0513)
 */
@RestController
@RequestMapping("/appSwiper")
@Api(value = "/appSwiper", tags = {"轮播图表 API接口"})
public class AppSwiperController extends BaseController{

    @Autowired
    public AppSwiperService appSwiperService;

    /**
     * 新增数据到【轮播图表】
     * @author 波波老师(weixin:javabobo0513)
     */
    @PostMapping(value="/save")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSwiper", name = "appSwiper", value = "")
    })
    @ApiOperation(value = "新增数据到【轮播图表】", notes = "新增数据到【轮播图表】", httpMethod = "POST")
    public JSONResult save(@RequestBody AppSwiper appSwiper){
        appSwiper.setCreateTime(DateUtils.getCurrentLocalDateTime());
        appSwiperService.save(appSwiper);
        return JSONResult.success(true);
    }

    /**
     * 修改【轮播图表】表数据
     * @author 波波老师(weixin:javabobo0513)
     */
    @PostMapping(value="/update")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSwiper", name = "appSwiper", value = "")
    })
    @ApiOperation(value = "修改【轮播图表】表数据", notes = "修改【轮播图表】表数据", httpMethod = "POST")
    public JSONResult update(@RequestBody AppSwiper appSwiper){
        appSwiperService.updateById(appSwiper);
        return JSONResult.success(true);
    }

    /**
     * 批量删除【轮播图表】数据
     * @author 波波老师(weixin:javabobo0513)
     */
    @PostMapping(value="/batchDelete")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSwiperQuery", name = "query", value = "")
    })
    @ApiOperation(value = "批量删除【轮播图表】数据", notes = "批量删除【轮播图表】数据", httpMethod = "POST")
    public JSONResult batchDelete(@RequestBody AppSwiperQuery query){
        //批量删除数据库数据
        appSwiperService.removeByIds(Arrays.asList(query.getIds()));
        return JSONResult.success(true);
    }

    /**
     * 单个删除【轮播图表】数据
     * @author 波波老师(weixin:javabobo0513)
    */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "")
    })
    @ApiOperation(value = "单个删除【轮播图表】数据", notes = "单个删除【轮播图表】数据", httpMethod = "DELETE")
    @DeleteMapping("/singleDelete/{id}")
    public JSONResult batchDelete(@PathVariable("id") Long id){
        //单个删除数据库数据
        appSwiperService.removeById(id);
        return JSONResult.success(true);
    }

    /**
    * 根据ID查询【轮播图表】详情数据
    * @author 波波老师(weixin:javabobo0513)
    */
    @GetMapping(value = "/{id}")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "")
    })
    @ApiOperation(value = "根据ID查询【轮播图表】详情数据", notes = "根据ID查询【轮播图表】详情数据", httpMethod = "GET")
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(appSwiperService.getById(id));
    }

    /**
    * 查询【轮播图表】所有数据（不分页）
    * @author 波波老师(weixin:javabobo0513)
    */
    @GetMapping(value = "/list")
    @ApiOperation(value = "查询【轮播图表】所有数据（不分页）", notes = "查询【轮播图表】所有数据（不分页）", httpMethod = "GET")
    public JSONResult list(){
        List<AppSwiper> list = appSwiperService.list(null);
        return JSONResult.success(list);
    }

    /**
     * 查询【轮播图表】数据（分页）
     * @param query 查询对象
     * @return PageList 分页对象
     * @author 波波老师(weixin:javabobo0513)
     */
    @PostMapping(value = "/pagelist")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataType = "AppSwiperQuery", name = "query", value = "查询对象")
    })
    @ApiOperation(value = "查询【轮播图表】数据（分页）", notes = "查询【轮播图表】数据（分页）", httpMethod = "POST")
    public JSONResult pagelist(@RequestBody AppSwiperQuery query){
        Page<AppSwiper> page = appSwiperService.selectMySqlPage(query);
        return JSONResult.success(new PageList<>(page.getTotal(), page.getRecords()));
    }

    /***********************************************************************************
    以上代码是自动生成的
    自己写的代码放在下面
    ***********************************************************************************/


    /**
     * APP端-获取指定类型的轮播图数据
     */
    @PostMapping(value = "/getListData")
    @IgnoreAuth
    public JSONResult getListData(@RequestBody AppSwiperQuery query){
        QueryWrapper<AppSwiper> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bus_type", query.getBusType());
        queryWrapper.orderByAsc("xuhao");
        List<AppSwiper> list = appSwiperService.list(queryWrapper);
        return JSONResult.success(list);
    }

}